﻿<UserControl x:Class="WpfImageDuplicates.DirectoryCollectionsViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:y="clr-namespace:WpfImageDuplicates"
             xmlns:dragdrop="clr-namespace:DragDropLibrary;assembly=DragAndDrop"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"                  
             mc:Ignorable="d">
    <!--dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"-->
    <Grid Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="1"/>
            <RowDefinition Height="24"/>            
            <RowDefinition Height="*"/>            
        </Grid.RowDefinitions>

        <Grid Grid.Row="1" HorizontalAlignment="Right" Canvas.ZIndex="99" VerticalAlignment="Center" Height="16">
            <Button x:Name="btnCloseView" Content="X" Click="btnCloseView_Click" Padding="4,0,4,0" Margin="0" ToolTip="Close View" FontSize="8" Canvas.ZIndex="99"/>
        </Grid>
        <Grid Grid.Row="1" Margin="0,0,16,0">
            <ToggleButton x:Name="btnAddGroup" Content="Add Group" Checked="btnAddGroup_Checked" IsChecked="False"
                          Visibility="{Binding Mode=OneWay, ElementName=btnAddGroup, Path=IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=NOT}"/>
            <Grid x:Name="groupNameStack" HorizontalAlignment="Stretch" 
                        Visibility="{Binding Mode=OneWay, ElementName=btnAddGroup, Path=IsChecked, Converter={StaticResource VisibilityConverter}}">
                <!--, ConverterParameter=NOT-->
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="6"/>
                    <ColumnDefinition Width="60"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="Name: " VerticalAlignment="Center" FontSize="10" />
                <TextBox Grid.Column="1" x:Name="txtNewGroupName" KeyDown="txtNewGroupName_KeyDown" MinWidth="80" VerticalAlignment="Center" FontSize="10" />
                <TextBlock Grid.Column="2" Text=" " VerticalAlignment="Center" />
                <Button Grid.Column="3" x:Name="btnCreateNewGroup" Content="Create" Click="btnCreateNewGroup_Click" VerticalAlignment="Center" Padding="2,1,2,1" FontSize="10"/>
            </Grid>
        </Grid>        
        <ListBox x:Name="lstGroups" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Row="2"
                 Margin="0,4,0,0"
                 dragdrop:DragAndDrop.RegisterDragSourceName="ImageCollectionView" 
                 dragdrop:DragAndDrop.RegisterDropTargetName="GroupView"
                 dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"    
                 dragdrop:DragAndDrop.DropEnabled="True"                                                                         
                 SelectionMode="Extended" 
                 SelectionChanged="lstGroups_SelectionChanged"
                 >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid x:Name="subGrid" Loaded="subGrid_Loaded" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="24"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="14"/>
                            <ColumnDefinition Width="14"/>
                            <ColumnDefinition Width="24"/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="0">
                            <CheckBox x:Name="chkSelect" IsChecked="{Binding Mode=OneWay, Path=IsSelected}" Checked="chkSelect_Checked" Unchecked="chkSelect_Unchecked" 
                                      Tag="{Binding}"/>
                        </Grid>
                        <Grid Grid.Column="1" HorizontalAlignment="Stretch">
                            <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="{Binding Name}" Tag="{Binding}" Cursor="Hand" TextDecorations="Underline"
                                       x:Name="txtGroupName" MouseLeftButtonDown="txtGroupName_MouseLeftButtonDown"
                                       Visibility="{Binding Mode=OneWay, Path=IsInEditMode, Converter={StaticResource VisibilityConverter}, ConverterParameter=NOT}" >
                                <TextBlock.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header="_Delete Group" x:Name="mnuDeleteGroup" Click="mnuDeleteGroup_Click" Tag="{Binding}"/>
                                        <MenuItem Header="_Rename Group" x:Name="mnuRename" Click="mnuRename_Click" Tag="{Binding}" />
                                    </ContextMenu>
                                </TextBlock.ContextMenu>
                            </TextBlock>
                            <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Center" x:Name="txtEditGroupName" KeyDown="txtEditGroupName_KeyDown" Tag="{Binding}"
                                     Visibility="{Binding Mode=OneWay, Path=IsInEditMode, Converter={StaticResource VisibilityConverter}}"
                                      IsVisibleChanged="txtEditGroupName_IsVisibleChanged" />
                        </Grid>
                        <Grid Grid.Column="2" HorizontalAlignment="Stretch">
                            <Image x:Name="btnDelete" Width="12" Height="Auto" Stretch="Uniform" Source="/WpfImageDuplicates;component/Images/Symbol%20Delete%202.png"
                                   ToolTip="Delete the group"
                                   Cursor="Hand" MouseLeftButtonDown="btnDelete_MouseLeftButtonDown" Tag="{Binding}" />
                        </Grid>
                        <Grid Grid.Column="3" HorizontalAlignment="Stretch">
                            <Image x:Name="btnEdit" Width="12" Height="Auto" Stretch="Uniform" Source="/WpfImageDuplicates;component/Images/Report%20Edit.png"
                                   ToolTip="Edit the Group Name"
                                   Cursor="Hand" MouseLeftButtonDown="btnEdit_MouseLeftButtonDown" Tag="{Binding}" />
                        </Grid>
                        <Grid Grid.Column="4" HorizontalAlignment="Stretch">
                            <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Count}" Tag="{Binding}"/>
                        </Grid>
                        
                        <Grid Grid.Row="1" x:Name="listOfFiles" Visibility="Collapsed" Grid.ColumnSpan="5" HorizontalAlignment="Left">
                            <ListBox x:Name="lstFileImagesInGroup" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                     Tag="{Binding}"
                                     SelectionMode="Extended">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid x:Name="subGrid2" Loaded="subGrid_Loaded" HorizontalAlignment="Stretch">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="4"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="16"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="1">
                                                <TextBlock Text="{Binding Directory}" VerticalAlignment="Center" />                                                
                                            </Grid>
                                            <Image Grid.Column="2" Source="/WpfImageDuplicates;component/Images/Symbol%20Delete%202.png" Width="14" Stretch="Uniform"
                                                   Tag="{Binding}"
                                                   Cursor="Hand" x:Name="removeFileImage" MouseLeftButtonDown="removeFileImage_MouseLeftButtonDown"/>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </Grid>
</UserControl>
